package me.wangcai.trafficpoliceai.service.impl;

import me.wangcai.trafficpoliceai.model.ResponseInfo;
import me.wangcai.trafficpoliceai.service.IVideoService;
import me.wangcai.trafficpoliceai.tasks.VideoTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class VideoServiceImpl implements IVideoService {

    private VideoTask videoTask = new VideoTask();
    private final String PATH = "E:/wangcai/a/video/";


    @Override
    public ResponseInfo playVideo(int index) {
        if(index >= getVideoList().size()) {
            return ResponseInfo.error("超出大小");
        }
        if(index == -1){
            videoTask.setNowVideo("404.mp4");
        }else{
            videoTask.setNowVideo(getVideoList().get(index));
        }
        return ResponseInfo.success("选择成功,稍后开始播放!");
    }

    @Override
    public List<String> getVideoList() {
        List<String> videoList = new ArrayList<>();
        for (File file : new File(PATH).listFiles()) {
            if(!file.getName().equalsIgnoreCase("404.mp4"))
            videoList.add(file.getName());
        }
        return videoList;
    }
}
